<?php
/**
 * Created by JetBrains PhpStorm.
 * User: Administrator
 * Date: 12-10-10
 * Time: 上午1:11
 * To change this template use File | Settings | File Templates.
 */
class Jwawa_Db_Profile extends  Zend_Db_Profiler
{
    public function queryEnd($queryId)
    {
        $state = parent::queryEnd($queryId);

        if (!$this->getEnabled() || $state == self::IGNORED) {
            return;
        }
        $log = Zend_Registry::get('log');
        // get profile of the current query
        $profile = $this->getQueryProfile($queryId);

        // update totalElapsedTime counter
        $this->_totalElapsedTime += $profile->getElapsedSecs();

        // create the message to be logged
        $message = "\r\nElapsed Secs: " . round($profile->getElapsedSecs(), 5) . "\r\n";
        $message .= "Query: " . $profile->getQuery() . "\r\n";
        // log the message as Debug message

        $log->debug($message);
        if(count($profile->getQueryParams()) > 0){
            $log->debug('SQL Parameter:' . PHP_EOL . print_r($profile->getQueryParams(), 1));
        }
    }
}
